package com.itheima.controller;

import com.alibaba.fastjson.JSON;
import com.itheima.domain.Product;
import com.itheima.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @author MI
 * @ClassName UserController.java
 * @createTime 2021年11月14日 22:36:00
 */
@Slf4j
@RestController
public class ProductController {
    @Autowired
    private ProductService productService;
    @RequestMapping("/product/{pid}")
    public Product product(@PathVariable("pid")Integer pid){
        log.info("接下来查询的是{}号商品",pid);
        Product product=   productService.findByPid(pid);
        /*try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }*/
        log.info("商品信息查询成功，内容为{}", JSON.toJSONString(product));
        return product;
    }
}
